
/**
 * @file    ble_bind.h
 * @author  Azolla (1228449928@qq.com)
 * @brief   ble bind ble-mesh device info.
 * @version 0.1
 * @date    2023-06-14
 * 
 * @copyright Copyright (c) 2023
 * */
#ifndef _BLE_BIND_H_
#define _BLE_BIND_H_

#include "ble_nvs.h"
#include "sdkconfig.h"

typedef struct {
    uint16_t uniaddr;        /**< device unicast addr. */
    uint8_t  pid;            /**< device product id. */
    uint8_t  addr[6];        /**< device mac addr. */
    char     name[16];       /**< device local name. */
} ble_mesh_bind_t;  // 设备绑定的基本信息


#ifndef CONFIG_BLE_MESH_MAX_PROV_NODES
#define CONFIG_BLE_MESH_MAX_PROV_NODES  1
#endif
typedef struct {
    ble_mesh_bind_t node[CONFIG_BLE_MESH_MAX_PROV_NODES];  // 最多存储多少个设备信息
    uint8_t update;
} __attribute__((packed)) ble_mesh_bind_nvs_t;  

//======================================================
void ble_mesh_bind_init(void);

bool ble_mesh_bind_add(ble_mesh_bind_t bind);

bool ble_mesh_bind_remove(uint16_t unicast_addr);

void ble_mesh_bind_update(void);

void ble_mesh_bind_remove_all(void);
//======================================================

char *ble_mesh_bind_find_name(uint8_t addr[6]);

bool ble_mesh_bind_find_addr(const char *name, uint8_t addr[6]);

bool ble_mesh_bind_find_addr_select(const char *name, uint8_t select, uint8_t addr[6]);


#endif /* _BLE_BIND_H_ end. */